package cn.dhnapplets.service.impl;

import cn.dhnapplets.entity.Order;
import cn.dhnapplets.entity.RecoverData;
import cn.dhnapplets.entity.tbOrderItem;
import cn.dhnapplets.mapper.QueryRecoveryDataMapper;
import cn.dhnapplets.service.QueryRecoveryDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 邱文彬
 * @Date 2021/12/2 10:52
 * @Version 1.0
 */


@Service
public class QueryRecoveryDataServiceImpl implements QueryRecoveryDataService {


    @Autowired
    private QueryRecoveryDataMapper queryRecoveryDataMapper;


    @Override
    public List<RecoverData> getAll() {

        List<Order> allAOne = queryRecoveryDataMapper.getAllA(1);
        List<tbOrderItem> allBOne = queryRecoveryDataMapper.getAllB(1);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String orderTime = formatter.format(allA.getOrderTime());;
        List<RecoverData> list = new ArrayList<>();
        int num = 0;
        for (Order order : allAOne) {
            for (tbOrderItem tbOrderItem : allBOne) {
                if(order.getId().equals(tbOrderItem.getOrderId())){
                    RecoverData recoverData = new RecoverData();
                    recoverData.setOrderNumber(order.getOrderNumber());
                    String orderTime = formatter.format(order.getOrderTime());
                    recoverData.setOrderTime(orderTime);
                    recoverData.setUserArea(order.getUserArea());
                    recoverData.setUserName(order.getUserName());
                    recoverData.setUserPhone(order.getUserPhone());
                    recoverData.setHorsemanName(order.getHorsemanName());
                    recoverData.setProductType(tbOrderItem.getProductType());
                    recoverData.setFinallyWeight(tbOrderItem.getFinallyWeight());
                    recoverData.setUnitPrice(tbOrderItem.getUnitPrice());
                    recoverData.setSum(tbOrderItem.getSum());
                    recoverData.setCategory("废旧纸类（元/kg）");
                    recoverData.setCity(order.getUserArea().substring(0,6));
                    list.add(num++,recoverData);
                    continue;
                }
            }
        }

        List<Order> allATwo = queryRecoveryDataMapper.getAllA(2);
        List<tbOrderItem> allBTwo = queryRecoveryDataMapper.getAllB(2);
        for (Order order : allATwo) {
            for (tbOrderItem tbOrderItem : allBTwo) {
                if(order.getId().equals(tbOrderItem.getOrderId())){
                    RecoverData recoverData = new RecoverData();
                    recoverData.setOrderNumber(order.getOrderNumber());
                    String orderTime = formatter.format(order.getOrderTime());
                    recoverData.setOrderTime(orderTime);
                    recoverData.setUserArea(order.getUserArea());
                    recoverData.setUserName(order.getUserName());
                    recoverData.setUserPhone(order.getUserPhone());
                    recoverData.setHorsemanName(order.getHorsemanName());
                    recoverData.setProductType(tbOrderItem.getProductType());
                    recoverData.setFinallyWeight(tbOrderItem.getFinallyWeight());
                    recoverData.setUnitPrice(tbOrderItem.getUnitPrice());
                    recoverData.setSum(tbOrderItem.getSum());
                    recoverData.setCategory("废旧塑料（元/kg）");
                    recoverData.setCity(order.getUserArea().substring(0,6));
                    list.add(num++,recoverData);
                    continue;
                }
            }
        }

        List<Order> allAthree = queryRecoveryDataMapper.getAllA(3);
        List<tbOrderItem> allBthree = queryRecoveryDataMapper.getAllB(3);
        for (Order order : allAthree) {
            for (tbOrderItem tbOrderItem : allBthree) {
                if(order.getId().equals(tbOrderItem.getOrderId())){
                    RecoverData recoverData = new RecoverData();
                    recoverData.setOrderNumber(order.getOrderNumber());
                    String orderTime = formatter.format(order.getOrderTime());
                    recoverData.setOrderTime(orderTime);
                    recoverData.setUserArea(order.getUserArea());
                    recoverData.setUserName(order.getUserName());
                    recoverData.setUserPhone(order.getUserPhone());
                    recoverData.setHorsemanName(order.getHorsemanName());
                    recoverData.setProductType(tbOrderItem.getProductType());
                    recoverData.setFinallyWeight(tbOrderItem.getFinallyWeight());
                    recoverData.setUnitPrice(tbOrderItem.getUnitPrice());
                    recoverData.setSum(tbOrderItem.getSum());
                    recoverData.setCategory("废旧金属类（元/kg）");
                    recoverData.setCity(order.getUserArea().substring(0,6));
                    list.add(num++,recoverData);
                    continue;
                }
            }
        }


        List<Order> allAFour = queryRecoveryDataMapper.getAllA(4);
        List<tbOrderItem> allBFour = queryRecoveryDataMapper.getAllB(4);
        for (Order order : allAFour) {
            for (tbOrderItem tbOrderItem : allBFour) {
                if(order.getId().equals(tbOrderItem.getOrderId())){
                    RecoverData recoverData = new RecoverData();
                    recoverData.setOrderNumber(order.getOrderNumber());
                    String orderTime = formatter.format(order.getOrderTime());
                    recoverData.setOrderTime(orderTime);
                    recoverData.setUserArea(order.getUserArea());
                    recoverData.setUserName(order.getUserName());
                    recoverData.setUserPhone(order.getUserPhone());
                    recoverData.setHorsemanName(order.getHorsemanName());
                    recoverData.setProductType(tbOrderItem.getProductType());
                    recoverData.setFinallyWeight(tbOrderItem.getFinallyWeight());
                    recoverData.setUnitPrice(tbOrderItem.getUnitPrice());
                    recoverData.setSum(tbOrderItem.getSum());
                    recoverData.setCategory("废旧纺织物（元/kg）");
                    recoverData.setCity(order.getUserArea().substring(0,6));
                    list.add(num++,recoverData);
                    continue;
                }
            }
        }


        System.out.println(list.size());
        return list;
    }
}
